package com.ifinc.common.socket.netty.client;

/**
 * Created by IntelliJ IDEA.
 * User: luotao
 * Date: 12-5-30
 * Time: 00:47
 */

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.*;
import org.springframework.stereotype.Service;

/**
 * 消息处理类
 */

public class ClientMessageHandler extends SimpleChannelHandler {


    @Override
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
            throws Exception {
        ChannelBuffer cb = (ChannelBuffer) e.getMessage();
        String content = new String(cb.array());
        System.out.println("content = " + content);
//        objectParserHandler.doReceived(content);

        e.getChannel().close();
    }

    @Override
    public void handleUpstream(
            ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
        super.handleUpstream(ctx, e);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
            throws Exception {
        e.getCause().printStackTrace();
        Channel ch = e.getChannel();
        ch.close();
    }

}
